*********************************************************************************************************************************************************************************
* This replication file generates the grid of counterfactual price reductions which will be considered when looking for the optimal level of price regulation under free entry. *
*********************************************************************************************************************************************************************************

clear all
capture log close 
set more off
set trace off
mata: mata set matastrict off
cd $main_directory

mata: districts=(1\2\3\4\5\6\8\9\10\11\12) //All judicial district identifiers (note: district 7 is skipped, since it is incorporated into district 3).
mata: p1_decrease=range(0,40,1) //Range of price reductions for real-estate transactions. This specific code states that price reductions from 0 to 40% should be considered.
mata: p2_decrease=range(0,40,1) //Range of price reductions for other transactions. This specific code states that price reductions from 0 to 40% should be considered.
//The next 4  lines generate a matrix with the following characteristics: 
//The first column corresponds to the district id (which range from 1 to 12, skipping district 7 which forms a joint legal entity with district 3).
//The second column corresponds to the price reduction in real-estate transactions.
//The third column corresponds to the price reduction in other transactions. 
mata: i_districts=J(length(p1_decrease)*length(p2_decrease),1,1)#districts
mata: i_p1=p1_decrease#J(length(districts)*length(p2_decrease),1,1)
mata: i_p2=J(length(p1_decrease),1,1)#(p2_decrease#J(length(districts),1,1))
mata: counterfactual_grid=(i_districts,i_p1,i_p2)
mata: mata matsave "Estimates/counterfactual_grid_free" counterfactual_grid, replace
